<template>
  <div class="Container">
    <div class="option">
      <!-- <el-button type="success" size="small" @click="addArea()">新增</el-button> -->
      <el-button type="primary" size="small" @click="Refresh()">刷新</el-button>
      <!--搜索 cashStatus userType  tradeNo -->
    </div>
    <el-table :data="List" border style="width: 100%">
      <el-table-column prop="index" label="序号"></el-table-column>

      <el-table-column prop="userName" label="用户号码"></el-table-column>
      <el-table-column prop="subName" label="支付宝账号"></el-table-column>

      <el-table-column prop="money" label="提现金额"></el-table-column>
      <!-- <el-table-column prop="reason" label="拒绝理由"></el-table-column> -->
      <!-- <el-table-column prop="auditTime" label="审核时间"></el-table-column> -->
      <el-table-column prop="tradeNo" label="交易流水单号 "></el-table-column>
      <el-table-column prop="userType" label="提现用户类型"></el-table-column>
      <el-table-column label="审核状态" width="260">
        <template slot-scope="scope">
          <el-button type="success" size="small" v-show="scope.row.cashStatus  == 1">审核成功</el-button>
          <el-button
            type="warning"
            size="small"
            v-show="scope.row.cashStatus  == 0"
            @click="pendding(scope.row)"
          >等待审核</el-button>
          <el-button type="danger" size="small" v-show="scope.row.cashStatus  == 2">审核失败</el-button>
        </template>
      </el-table-column>

      <el-table-column fixed="right" label="操作" width="240">
        <template slot-scope="scope">
          <!-- <el-button @click="handleClick(scope.row)" type="primary" size="small">查看</el-button> -->
          <!-- <el-button @click="EditClick()" type="primary" plain size="small">编辑</el-button> -->
          <el-button  v-show="scope.row.cashStatus !== 0"
          @click="DeleteClick(scope.row)" type="danger" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="paginat">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage4"
        :page-size="10"
        layout="total, prev, pager, next"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      List: [],
      total: 0,
      val: 1, //当前多少页
      currentPage4: 1,
      status: 0
    };
  },
  created() {
    this.getList();
  },
  methods: {
    pendding(row) {
      row.userType  = row.userType == "个人盈利" ? 0 : 1
      this.$confirm("提现审核,是否通过", "提示", {
        confirmButtonText: "通过",
        cancelButtonText: "不通过",
        type: "warning"
      })
        .then(() => {
          this.status = 1;
          let url = "/cash/verify";
          let params = {
            id: row.id,
            money: row.money,
            status: this.status,
            userId: row.userId
          };
          this.httpPost(url, params, res => {
            if (res.code == 200) {
              this.$message({
                type: "success",
                message: "通过"
              });
              this.getList();
            }
          });
        })
        .catch(() => {
          this.status = 2;
          let url = "/cash/verify";
          let params = {
            id: row.id,
            money: row.money,
            status:  this.status,
            type: row.userType,
            userId: row.userId
          };
          console.log(row);
          this.httpPost(url, params, res => {
            if (res.code == 200) {
              this.$message({
                type: "info",
                message: "不通过"
              });
              this.getList();
            }
          });
        });
    },
    //分页
    handleCurrentChange(val) {
      this.val = val;
      this.getList();
      console.log(`当前页: ${val}`);
    },
   

    //刷新
    Refresh() {
      this.getList();
    },
    //查看
    handleClick() {
      this.$router.push("/checkArea");
    },
    //编辑
    EditClick() {},
   //删除
    DeleteClick(row) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let url = "/cash/edit";
          let params = {
            id: row.id,
            status: 1
          };
          this.httpPut(url, params, res => {
            if (res.code == 200) {
              this.$message({
                type: "success",
                message: "删除成功"
              });
              this.dialogVisible = false;
              this.getList();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    //获取数据
    getList() {
      let url = "/cash/findList";
      let params = {
        pageNum: this.val,
        pageSize: 10
      };
      this.httpPost(url, params, res => {
        if (res.code == 200) {
          this.List = res.data.list;
          this.total = res.data.total;
          this.List.forEach((element, i) => {
        this.List[i].index = (this.val - 1) * 10 + i + 1;
            this.List[i].userType =
              this.List[i].userType == 0 ? "个人盈利" : "推荐奖励";
          });
        } else {
          console.log("查询失败");
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.Container {
  .option {
    padding: 10px;
  }
  .el-button + .el-button {
    margin-left: 0px !important;
  }
}
</style>


